package com.lntea.crawler.website.controller;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lntea.crawler.bannerdata.service.BannerDataService;
import com.lntea.crawler.entity.BannerData;
import com.lntea.crawler.entity.Picture;
import com.lntea.crawler.entity.Website;
import com.lntea.crawler.picture.service.PictureService;
import com.lntea.crawler.website.service.WebsiteService;

@Controller
@RequestMapping("website")
public class WebsiteController {
	
	@Autowired
	private WebsiteService websiteService;
	@Autowired
	private BannerDataService bannerDataService;
	@Autowired
	private PictureService pictureService;
	
	@RequestMapping("/list.html")
	public String list(Model model){
		Map<String, List<Picture>> map = new HashMap<String, List<Picture>>();
		List<Website> websiteList = websiteService.queryAllWebsite();
		
		List<Long> ids = new LinkedList<Long>();
		for(Website website : websiteList){
			ids.add(website.getWebsiteId());
		}
		
		map = websiteService.queryPictureByWebsiteIds(ids);
		/*for(Website website : websiteList){
			List<BannerData> bannerDataList = 
					bannerDataService.queryBannerDataByWebsiteId(website.getWebsiteId());
			BannerData bannerData = bannerDataList.get(0);
			List<Picture> pictureList = pictureService.queryPictureByBannerDataId(bannerData.getBannerId());
			map.put(website.getWebsiteName(), pictureList);
		}*/
		model.addAttribute("websiteMap", map);
		return "list";
	}
}
